package com.ithe;

import java.util.Collection;
import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetDemo {
    public static void main(String[] args) {
        test1();
        extracted();

    }

    private static void extracted() {
        TreeSet<Integer> set1 = new TreeSet<>();

//        Integer i1 = Integer.valueOf(1);--->自动拆箱

        //1--->包装成Integer-->自动装箱

        set1.add(1);
        set1.add(2);
        set1.add(5);
        set1.add(4);
        set1.add(3);
        for (Integer integer : set1) {
            System.out.println(integer);
        }
        System.out.println(set1);
    }
    public static void test1() {
        Comparator<Student> comparator = (o1, o2) -> o1.getAge() - o2.getAge();
        TreeSet<Student> set = new TreeSet<>(comparator);
        set.add(new Student("A", 20, "男", "123"));
        set.add(new Student("X", 21, "女", "456"));
        set.add(new Student("B", 22, "男", "146"));
        for (Student student : set) {
            System.out.println(student.getName() + "-" + student.getAge());
        }

    }
    public static int sum(int... a) {
        int total = 0;
        for (int i = 0; i < a.length; i++){
            total += a[i];
        }
        return total;
    }
}
